using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace Sec_scan漏洞扫描系统
{
    public partial class Sec_Scan_ScanInfo : Form
    {
        public Sec_Scan_ScanInfo()
        {
            InitializeComponent();
        }

        private void pictureBox11_Click(object sender, EventArgs e)
        {
            Close();
        }
        public int oldX, oldY;
        public int CounKs;
        private void panel1_MouseDown(object sender, MouseEventArgs e)
        {
            //判断是否为鼠标左键
            if (e.Button == MouseButtons.Left)
            {
                //获取鼠标左键按下时的位置
                this.oldX = e.Location.X;
                this.oldY = e.Location.Y;
            }
        }
        private void ScanInfo_Load(object sender, EventArgs e)
        {
            try
            {
                this.dataGridView2.AutoGenerateColumns = false;//必须得设置为false,否则无法显示数据
                dataGridView2.ColumnHeadersDefaultCellStyle.Alignment = DataGridViewContentAlignment.MiddleCenter;
                //DataTable dt = new DataTable();
                //dt.Columns.Add("Column7");
                //dt.Columns.Add("Column1");
                //加载漏洞信息
                string s1 = Sec_Api.Sec_LoopScan_Service_Api.UrlBase.ToString();
                string s2 = Sec_Api.Sec_LoopScan_Service_Api.Loopname.ToString();
                string s3 = Sec_Api.Sec_LoopScan_Service_Api.Loopnumber.ToString();
                string s4 = Sec_Api.Sec_LoopScan_Service_Api.Looptype.ToString();
                string[] s1Array = s1.Split(new char[] { '\r', '\n' }, StringSplitOptions.RemoveEmptyEntries);
                string[] s2Array = s2.Split(new char[] { '\r', '\n' }, StringSplitOptions.RemoveEmptyEntries);
                string[] s3Array = s3.Split(new char[] { '\r', '\n' }, StringSplitOptions.RemoveEmptyEntries);
                string[] s4Array = s4.Split(new char[] { '\r', '\n' }, StringSplitOptions.RemoveEmptyEntries);

                int i = 0;
                foreach (String s in s1Array)
                {
                    dataGridView2.Rows[i].Cells[0].Value = s;
                    i++;
                }
            }
            catch(Exception ex)
            {
                MessageBox.Show(ex.ToString());
            }
           

            //string payload = Sec_Api.Sec_LoopScan_Service_Api.UrlBase.ToString();
            //string[] lase = payload.Split(new char[] { '\r', '\n' }, StringSplitOptions.RemoveEmptyEntries);
            //foreach (string bs in lase)
            //{
            //    CounKs++;
            //    dataGridView2.Rows.Add(CounKs,bs,DateTime.Now);
            //}
        }

        private void 查看详情ToolStripMenuItem1_Click(object sender, EventArgs e)
        {
            //查看漏洞 获取选择行
            var dataselect = this.dataGridView2.SelectedRows;
            if(dataselect.Count > 0)
            {
                //string s1 = Sec_Api.Sec_LoopScan_Service_Api.Url.ToString();
                //string s2 = Sec_Api.Sec_LoopScan_Service_Api.UrlBase.ToString();
                foreach (DataGridViewRow row in dataselect)
                {
                    String s1 = Convert.ToString(dataselect[0].Cells["Column1"].Value);
                    String s2 = Convert.ToString(dataselect[0].Cells["Column7"].Value);
                    String s3 = Convert.ToString(dataselect[0].Cells["Column2"].Value);
                    Sec_Config.Sec_CacheInfo.CacheInsert("s4",s1);
                    Sec_Config.Sec_CacheInfo.CacheInsert("s5", s2);
                    Sec_Config.Sec_CacheInfo.CacheInsert("s6", s3);
                    Console.WriteLine(s1);
                    Console.WriteLine(s2);
                    Console.WriteLine(s3);
                    Sec_Scan_LoopListCat cat = new Sec_Scan_LoopListCat();
                    cat.StartPosition = FormStartPosition.CenterScreen;
                    cat.ShowDialog();
                }
                //Console.WriteLine(s1);
                //Console.WriteLine(s2);
            }

            //LoopListCat cat = new LoopListCat();
            //cat.StartPosition = FormStartPosition.CenterScreen;
            //cat.ShowDialog();
        }

        private void panel1_MouseMove(object sender, MouseEventArgs e)
        {
            if (e.Button == MouseButtons.Left)
            {
                //计算鼠标移动距离
                this.Left += e.Location.X - this.oldX;
                this.Top += e.Location.Y - this.oldY;
            }
        }
    }
}
